import { CrudBack, R, SysDept, SysUser } from "@/interface/user";
import { AxiosResponse } from "axios";
import request from '../utils/request'
import { Page } from "@/interface/log";

// 响应接口
export interface DeptAllTreeRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: SysDept[];
}

/** 
 * 部门列表(树形)
 * @returns
 */
export function deptAllTreeApi(): Promise<AxiosResponse<DeptAllTreeRes>> {
  return request.get(`/sys/dept/all/tree`, {
    headers: {
      isToken: true
    }
  });
}

// 响应接口
export interface GetDeptUserAllRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: Page<SysUser[]>;
}

/** 
 * 部门用户列表
 * @param {string} current 
  * @param {string} pageSize 
  * @param {string} deptId 
  * @returns
 */
export function getDeptUserAllApi(current: number, pageSize: number, deptId: number): Promise<AxiosResponse<GetDeptUserAllRes>> {
  return request.get(`/sys/dept/user/dept?current=${current}&pageSize=${pageSize}&deptId=${deptId}`, {
    headers: {
      isToken: true
    }
  });
}

export function addDeptApi(params: SysDept): Promise<AxiosResponse<CrudBack>> {
  return request.post(`/sys/dept/add`, params, {
    headers: {
      isToken: true
    }
  });
}

export function getDeptPlainApi(): Promise<AxiosResponse<R<SysDept[]>>> {
  return request.get(`/sys/dept/all/plain`, {
    headers: {
      isToken: true
    }
  });
}

export function updateDeptApi(params: SysDept): Promise<R<any>> {
  return request.post(`/sys/dept/update`, params, {
    headers: {
      isToken: true
    }
  });
}

export function deleteDeptApi(ids: string): Promise<R<any>> {
  return request.post(`/sys/dept/delete/${ids}`, null,{
    headers: {
      isToken: true
    }
  });
}